#!/usr/bin/python
# -*- coding:utf-8 -*-

import wx

class Example(wx.Frame):
    
    def __init__(self, *args, **kwds):
        super(Example, self).__init__(*args, **kwds)
        
        self.InitUI()

    def InitUI(self):
        panel = wx.Panel(self)
        self.color = wx.Color(0, 0, 0)
        rtb = wx.ToggleButton(panel, label='Red', pos=(20, 25))
        gtb = wx.ToggleButton(panel, label='Green', pos=(20, 60))
        btb = wx.ToggleButton(panel, label='Blue', pos=(20, 100))

        self.cpanel = wx.Panel(panel, pos=(150, 20), size=(110, 110))
        self.cpanel.SetBackgroundColour(self.color)

        rtb.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleRed)
        gtb.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleGreen)
        btb.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleBlue)

        self.SetSize((300, 200))
        self.SetTitle('Toggle Buttons')
        self.Centre()
        self.Show(True)
        

    def ToggleRed(self, e):
        obj = e.GetEventObject()
        isPressed = obj.GetValue()

        green = self.color.Green()
        blue = self.color.Blue()
        
        if isPressed:
            self.color.Set(255, green, blue)
        else:
            self.color.Set(0, green, blue)

        self.cpanel.SetBackgroundColour(self.color)

    def ToggleGreen(self, e):

        obj = e.GetEventObject()
        isPressed = obj.GetValue()

        red = self.color.Red()
        blue = self.color.Blue()
        
        if isPressed:
            self.color.Set(red, 255, blue)
        else:
            self.color.Set(red, 0, blue)

        self.cpanel.SetBackgroundColour(self.color)

    def ToggleBlue(self, e):

        obj = e.GetEventObject()
        isPressed = obj.GetValue()

        red = self.color.Red()
        green = self.color.Green()
        
        if isPressed:
            self.color.Set(red, green, 255)
        else:
            self.color.Set(red, green, 0)

        self.cpanel.SetBackgroundColour(self.color)

def main():
    ex = wx.App()
    Example(None)
    ex.MainLoop()

if __name__ == '__main__':
    main()
